/**
 * @Description:提示
 * @author TangYong
 * @date 2022/12/14
 */
import React, {Component} from 'react';
import RootToast from 'react-native-root-toast';
import {View, Text, Platform, StyleSheet, Dimensions} from 'react-native';
// import Icon from 'react-native-vector-icons/FontAwesome'
let width = Dimensions.get('window').width;
const Toast = {

    toast: null,

    show: (msg, options) => {
        this.toast = RootToast.show(msg,
            {
                position: 40,
                duration: 1500,
                // animation: true, // toast显示/隐藏的时候是否需要使用动画过渡
                // hideOnPress: false, // 是否可以通过点击事件对toast进行隐藏
                // shadow: true, // toast是否出现阴影
                textColor: '#02081A',
                backgroundColor: '#F8FEFF',
                // opacity:0.5
            },

                msg, {
                // position: 40,
                // duration: 1500,
                // animation: true, // toast显示/隐藏的时候是否需要使用动画过渡
                // hideOnPress: false, // 是否可以通过点击事件对toast进行隐藏
                // shadow: true, // toast是否出现阴影
                textColor:"#02081A",
                backgroundColor:"#F8FEFF",
                //opacity:0.5
            }
        );
    },

    showLong: msg => {
        this.toast = RootToast.show(msg, {
            position: 0,
            duration: 2000,
        });
    },
    showWarning: (msg, options) => {
        if (msg.toString().indexOf('Error') !== -1) {
            msg= msg.replace('Error','提示')
        }


        let toast = RootToast.show(
            Platform.OS === 'ios' ?
                <View style={styles.container}>
                    {/*<Icon name='warning' size={40} color={'#E9A94E'}/>*/}
                    {/*{msg}*/}
                    <Text style={styles.message}>{msg}</Text>
                </View> : msg, {
                duration: RootToast.durations.SHORT,
                position: RootToast.positions.CENTER,
                textColor: '#F7F7F7',
                backgroundColor: '#535252',
                shadow: false, // toast是否出现阴影
                ...options,
            });
        setTimeout(function () {
            RootToast.hide(toast);
        }, RootToast.durations.SHORT + 500);
    },


    // showLongSuccess: (msg, options) => {
    //     let toast = RootToast.show(
    //         Platform.OS === 'ios' ?
    //             <View style={styles.container}>
    //                 {/*<Icon name='check' size={50} color={'#fff'}/>*/}
    //                 <Text style={styles.message}>{msg}</Text>
    //             </View> : msg, {
    //             duration: 2000,
    //             position: RootToast.positions.CENTER,
    //             ...options,
    //         });
    //     setTimeout(function () {
    //         RootToast.hide(toast);
    //         typeof options === 'function' ? options && options() : null;
    //     }, 2500);
    // },


};

let styles = StyleSheet.create({
    container: {
        alignItems: 'center',
        justifyContent: 'center',
    },
    message: {
        color: '#F7F7F7',
        marginTop: 5,
        fontSize: 16,
        fontWeight: 'bold',
        textAlign: 'center',
        lineHeight: 0,
    },
});

export {Toast};
